
//jQuery.noConflict(); // Avoid conflicts with the RichFaces/Prototype library

function showCatetoryDiv(){
//jQuery("taskForm\\:categoryDiv").show();
document.getElementById("taskForm:categoryDiv").style.display="block";
}

function hideCategoryDiv(){
document.getElementById("taskForm:categoryDiv").style.display="none";
}
        function jsf(id) {
            // Find the dynamic JSF client identifier by looking up
            // the static identifier of its j4j proxy child element
            if (document.getElementById(id) == null) { alert("Couldn't find JSF element: " + id); }
            var realId = document.getElementById(id).title;
            var element = document.getElementById(realId);
            return jQuery(element);
        }


function getObjectByJSFId(id){
var formId="projectForm";
 if (document.getElementById(id) == null) { alert("Couldn't find JSF element: " + id); }
return document.getElementById(id);

}

function returnBudgetValue(){
alert(document.getElementById("projectForm:aa:budget").value);
//return jsf(budget).value;
}


function UserName() {
	return "";//GetUserNameFromCookie();
}

var sessionID = "";//GetUserSessionIDFromCookie();

var userName = UserName();

function head_mytinosearch() {
	var keyword = (document.getElementById("mytinosearch_keyword").value)
			.trim();
	var keyword_type = document.getElementById("select_type").value;
	keyword = encodeURIComponent(keyword);
	var re = /\+/;
	keyword = keyword.replace(re, '%2B');

	if (keyword.replace(/[ ]/g, "") == "" || keyword == null
			|| keyword == "myTino%20Search") {
		if (keyword_type == "select_jobs") {
			location.href = "search/index.php?searcharea=job";
		} else {
			location.href = "search/index.php?searcharea=pro";
		}
	} else {
		if (keyword_type == "select_jobs") {
			location.href = "search/job_search.php?tt=" + keyword;
		} else {
			location.href = "search/provider_search.php?keywords=" + keyword;
		}
	}
}

function delCookie(name) {
	var date = new Date();
	date.setTime(date.getTime() - 10000);
	document.cookie = name + "=a; expires=" + date.toGMTString()
			+ "; path=/; domain=.mytino.com";
}

function head_cook_signout() {
	delCookie("UserName");
	delCookie("IDSession");
	location.reload(true);
}

var dhmenu = new Array;
dhmenu[0] = "level_0_div";
dhmenu[1] = "level_1_div";
dhmenu[2] = "level_2_div";
function showMenu(n) {
	var obj = document.getElementById(dhmenu[n]);
	if (obj.style.visibility == "visible")
		return;
	obj.style.visibility = "visible";
	for (i = 0; i < 2; i++) {
		mObj = document.getElementById(dhmenu[i]);
		if (i != n)
			mObj.style.visibility = "hidden";
	}
}

function hideMenu(n) {
	var obj = document.getElementById(dhmenu[n]);
	obj.style.visibility = "hidden";
}

function head_sess_signout() {
	var userName = "";
	var rand = Math.random();
	if (userName) {
		var x = new XHR("re_login");
		var url = "loginout.php?rand=" + rand;
		x.get(url);
	} else {
		location.href = "sign_in.php";
	}
}
function re_login(ret) {
	if (ret == '1') {
		location.href = "index.php";
	}
}

function checkname() {
	var rand = parseInt(Math.random() * 10000);
	var name = document.getElementById("name").value;
	var email = document.getElementById("email").value;
	var str = name.trim();
	var pattern = /^[0-9a-zA-Z]{3,20}$/;
	flag = pattern.test(str);
	if (name == "") {
		document.getElementById("nameinfo").className = "forange1";
		document.getElementById("nameinfo").innerHTML = "请输入昵称";
	} else if (!flag) {
		document.getElementById("nameinfo").className = "forange1";
		document.getElementById("nameinfo").innerHTML = "昵称格式不正确！昵称由3-20个字母或数字组成.";
	} else {
		/*
		 * var x = new XHR ('reg_checkname'); var url =
		 * "common/check_reg.php?name="+name+"&mail="+email+"&rand"+rand;
		 * x.get(url);
		 */
	}
}
function reg_checkname(ret) {
	var nameinfo = document.getElementById("nameinfo");
	if (ret == 1) {
		nameinfo.className = "fgreen";
		nameinfo.innerHTML = "ok";
	} else if (ret == 0) {
		nameinfo.className = "forange1";
		nameinfo.innerHTML = "此昵称已经被使用";
		return false;
	} else {
		nameinfo.className = "forange1";
		nameinfo.innerHTML = "此昵称不允许使用，请重新选取";
		return false;
	}
}
function checkemail() {
	var rand = parseInt(Math.random() * 10000);
	var email = document.getElementById("email").value;
	if (email == "") {
		document.getElementById("emailinfo").className = "forange1";
		document.getElementById("emailinfo").innerHTML = "请输入您的邮箱";
	} else if (check_email(email)) {
		document.getElementById("emailinfo").className = "forange1";
		document.getElementById("emailinfo").innerHTML = "邮箱格式不正确";
	} else {
		/*
		 * var x = new XHR ('re_checkemail'); var url =
		 * "common/check_reg.php?email="+email+"&rand"+rand; x.get(url);
		 */
	}
}
function re_checkemail(ret) {
	var emailinfo = document.getElementById("emailinfo");
	if (ret == 1) {
		emailinfo.className = "fgreen";
		emailinfo.innerHTML = "ok";
		document.getElementById("passwd").focus();
	} else {
		emailinfo.className = "forange1";
		emailinfo.innerHTML = "";// 此邮箱已经被使用";
		// return false;
	}
}
function checkpasswordEx() {
	var passwd = document.getElementById("passwd").value;
	if (passwd == "") {
		document.getElementById("confirm_passwd").disabled = true;
	} else if (checkSafe(passwd)) {
		document.getElementById("confirm_passwd").disabled = true;
	} else {
		document.getElementById("confirm_passwd").disabled = false;
	}
}
function checkpasswd() {
	var passwd = document.getElementById("passwd").value;
	var passinfo = document.getElementById("passinfo");
	if (passwd == "") {
		passinfo.className = "forange1";
		passinfo.innerHTML = "请输入正确的密码.";
		document.getElementById("confirm_passwd").disabled = true;
	} else if (checkSafe(passwd)) {
		passinfo.className = "forange1";
		passinfo.innerHTML = "请输入正确的密码！密码由6-16个字母或数字组成.";
		document.getElementById("confirm_passwd").disabled = true;
	} else {
		passinfo.className = "fgreen";
		passinfo.innerHTML = "ok";
		document.getElementById("confirm_passwd").disabled = false;
		if (document.getElementById("confirm_passwd").value != '')
			confirmpasswd();
	}
}
function confirmpasswd() {
	var passwd = document.getElementById("passwd").value;
	var confirm_passwd = document.getElementById("confirm_passwd").value;
	var confirm_passinfo = document.getElementById("confirm_passinfo");
	if (passwd != confirm_passwd) {
		confirm_passinfo.className = "forange1";
		confirm_passinfo.innerHTML = "两次输入密码不一致";
		return false;
	} else {
		confirm_passinfo.className = "fgreen";
		confirm_passinfo.innerHTML = "ok";
		return true;
	}

}
function refreshCc() {
	var ccImg = document.getElementById("checkCodeImg");
	document.getElementById("ck").value = '';
	var ckinfo = document.getElementById("ckinfo");
	var rand = parseInt(Math.random() * 10000);
	ccImg.src = "common/ck.php?a=" + rand;
	ckinfo.className = "";
	ckinfo.innerHTML = "";
}
function Init() {
	refreshCc();
}
function check_sub() {
	if ($("#email").val()) {
		var user = Seam.Component.newInstance("user");
		user.setEmail($("#email").val());
		user.setPassword($("#passwd").val());
		user.setNickName($("#name").val());
		Seam.Component.getInstance("userAction").register(user,
				registerCallback);
	} else {
		alert("请输入Email!...");
	}
}

function registerCallback() {
	alert("注册成功!");
	window.location.href = "../index.jsp";
}

function foucus(m) {
	if (m == 1) {
		document.getElementById("emailinfo").innerHTML = "账户激活邮件将发送至该邮箱";
		document.getElementById("emailinfo").className = "idx_font_gray";
	} else if (m == 2) {
		document.getElementById("passinfo").innerHTML = "由6-16个字母或数字组成";
		document.getElementById("passinfo").className = "idx_font_gray";
	} else if (m == 3) {
		document.getElementById("confirm_passinfo").innerHTML = "再输入一遍您的密码以确保没有输错";
		document.getElementById("confirm_passinfo").className = "idx_font_gray";
	} else if (m == 4) {
		document.getElementById("nameinfo").innerHTML = "您在affectu平台显示的名字，由3-20个字母或数字组成";
		document.getElementById("nameinfo").className = "idx_font_gray";
	}
}